<#-- WARNING : be careful to white-space and lines break in FreeMarker macros.
 # This macro template can be used to output white-space-sensitive formats (like RSS files).
 # See http://dev.lutece.paris.fr/jira/browse/LUTECE-765
-->
<#include "util/standard/macro_standard.html" />
<#include "util/calendar/macro_datepicker.html" />
<#-- Do not remove this comment -->

<#macro comboSiteWithParams name default_value additionalParameters items >
	<select id="${name}" name="${name}" ${additionalParameters} >
		<#list items as item>
			<#if default_value="${item.code}">
				<option selected="selected" value="${item.code}" >${item.name}</option>
		   	<#else>
		   		<option value="${item.code}" >${item.name}</option>
		   	</#if>
		</#list>		
	</select>
</#macro>

<#macro comboSiteSortedWithParams name default_value additionalParameters items >
	<select id="${name}" name="${name}" ${additionalParameters} >
		<#list items?sort_by("name") as item>
			<#if default_value="${item.code}">
				<option selected="selected" value="${item.code}" >${item.name}</option>
		   	<#else>
		   		<option value="${item.code}" >${item.name}</option>
		   	</#if>
		</#list>		
	</select>
</#macro>

<#macro comboSiteWithParamsAndLength name default_value additionalParameters items max_length >
	<select id="${name}" name="${name}" ${additionalParameters} >
		<#list items as item>
    	    <#if max_length < item.name?length >
            	<#assign item_new = "..." + "${item.name?substring(item.name?length-max_length+3)}" >
            <#else>
              	<#assign item_new = "${item.name}">
            </#if>	
			<#if default_value="${item.code}"> 			
      			<option selected="selected" value="${item.code}" >${item_new}</option>
      		<#else>
      			<option value="${item.code}" >${item_new}</option>
      		</#if>
    	</#list>		
	</select>
</#macro>

<#macro comboSite name default_value items >
	<@comboSiteWithParams name="${name}" default_value="${default_value}" additionalParameters="" items=items />
</#macro>

<#macro comboSiteSorted name default_value items >
	<@comboSite name="${name}" default_value="${default_value}" items=items?sort_by("name") />
</#macro>

<#macro sortSite jsp_url attribute id="" >
	<#if jsp_url?contains("?")>
		<#assign sort_url = jsp_url + "&amp;sorted_attribute_name=" + attribute + "&amp;asc_sort=" />
	<#else>
		<#assign sort_url = jsp_url + "?sorted_attribute_name=" + attribute + "&amp;asc_sort=" />
	</#if>
	<a id="sort${id!}_${attribute!}" href="${sort_url}true#sort${id!}_${attribute!}" title="#i18n{portal.util.sort.asc}" >
		<i class="icon-chevron-up">&nbsp;</i>
	</a>
	<a href="${sort_url}false#sort${id!}_${attribute!}" title="#i18n{portal.util.sort.desc}">
    	<i class="icon-chevron-down">&nbsp;</i>
    </a>
</#macro>

<#macro paginationSite paginator combo=0 form=1 nb_items_per_page=nb_items_per_page >
	<#if (paginator.pagesCount > 1) >
		<@paginationSitePageLinks paginator=paginator />
	</#if>
	<#if form == 1 >
		<form method="post" action="">
	</#if>
		<div class="row-fluid">
			<div class="pull-right" >
				<div class="form-inline">
					<@paginationSiteItemCount paginator=paginator combo=combo nb_items_per_page=nb_items_per_page/>
				</div>
			</div>
		</div>
	<#if form == 1 >
		</form>
	</#if>
	<div class="table"></div>
 </#macro>

 <#macro paginationSitePageLinks paginator >
	<#assign nbLinkPagesToDisplay = 10 />
	<#assign offsetPrev = nbLinkPagesToDisplay / 2 />
	<#assign offsetNext = nbLinkPagesToDisplay / 2 />
	<#if ( paginator.pageCurrent <= nbLinkPagesToDisplay - offsetPrev )>
		<#assign offsetPrev = paginator.pageCurrent - 1 />
		<#assign offsetNext = nbLinkPagesToDisplay - offsetPrev />
	<#elseif ( paginator.pageCurrent + offsetNext > paginator.pagesCount )>
		<#assign offsetNext = paginator.pagesCount - paginator.pageCurrent />
		<#assign offsetPrev = nbLinkPagesToDisplay - offsetNext />
	</#if>
	<div class="pagination pagination-centered">
		<ul>
			<#if ( paginator.pageCurrent - offsetPrev > 1 )>
				<li>
					<a href="${paginator.firstPageLink?xhtml}">
						${paginator.labelFirst}
					</a>
				</li>
			</#if>
			<#if (paginator.pageCurrent > 1) >
				<li class="previous">
					<a href="${paginator.previousPageLink?xhtml}">
						${paginator.labelPrevious}
					</a>
				</li>
			<#else>
				<li class="disabled">
					<a href="${paginator.firstPageLink?xhtml}">${paginator.labelPrevious}</a>
				</li>
			</#if>
			<#if ( paginator.pageCurrent - offsetPrev > 1 )>
				<li>
					<a href="${(paginator.pagesLinks?first).url?xhtml}"><strong>...</strong></a>
				</li>
			</#if>
			<#list paginator.pagesLinks as link>
				<#if ( link.index == paginator.pageCurrent )>
					<li class="active">
						<a href="${link.url?xhtml}">${link.name}</a>
					</li>
				<#else>
					<li>
						<a href="${link.url?xhtml}">${link.name}</a>
					</li>
				</#if>
			</#list>
			<#if ( paginator.pageCurrent + offsetNext < paginator.pagesCount )>
				<li>
					<a href="${(paginator.pagesLinks?last).url?xhtml}"><strong>...</strong></a>
				</li>
			</#if>
			<#if (paginator.pageCurrent < paginator.pagesCount) >
				<li class="next">
					<a href="${paginator.nextPageLink?xhtml}">
					${paginator.labelNext}
					</a>
				</li>
				<#if ( paginator.pageCurrent + offsetNext < paginator.pagesCount )>
					<li class="next">
						<a href="${paginator.lastPageLink?xhtml}">
							${paginator.labelLast}
						</a>
					</li>
				</#if>
			<#else>
				<li class="disabled">
					<a href="${paginator.lastPageLink?xhtml}">${paginator.labelNext}</a>
				</li>
			</#if>
		</ul>
	</div>
 </#macro>
 
<#macro paginationSiteCombo paginator nb_items_per_page=nb_items_per_page>
	<span class="add-on">${paginator.labelItemCountPerPage}</span>
	<select class="input-mini" name="${paginator.itemsPerPageParameterName}" id="${paginator.itemsPerPageParameterName}" title="${paginator.labelItemCountPerPage}">
		<#list [ "10" , "20" , "50" , "100" ] as nb>
			<#if nb_items_per_page = nb >
				<option selected="selected" value="${nb}">${nb}</option>
			<#else>
			  	<option value="${nb}">${nb}</option>
			</#if>
		</#list>
	</select>
	<button class="btn btn-small" type="submit" title="#i18n{portal.util.labelRefresh}"/>
		<i class="icon-repeat"></i>
	</button>
	&nbsp;-&nbsp;
</#macro>

<#macro paginationSiteItemCount paginator combo=0 nb_items_per_page=nb_items_per_page>
	<#-- Display combo -->
	<#if combo == 1 >
		<@paginationSiteCombo paginator=paginator nb_items_per_page=nb_items_per_page/>
	</#if>
	<#-- Display item count -->
	<#if (paginator.labelItemCount)?? && paginator.labelItemCount?has_content>${paginator.labelItemCount} : </#if>${paginator.itemsCount}
</#macro>


<#macro item_navigationSite item_navigator>
	<div id="item-navigator">
		<#if (item_navigator.currentItemId > 0)>
			<a href="${item_navigator.previousPageLink?xhtml}" title="#i18n{portal.util.labelPrevious}">
				<i class="icon-circle-arrow-left"></i>
				#i18n{portal.util.labelPrevious}
			</a>
		<#else>
			&nbsp;&nbsp;
		</#if>
		<#if (item_navigator.currentItemId < item_navigator.listItemSize - 1) >
			<a href="${item_navigator.nextPageLink?xhtml}" title="#i18n{portal.util.labelNext}">
				#i18n{portal.util.labelNext}
				<i class="icon-circle-arrow-right"></i>
			</a>
		<#else>
			&nbsp;&nbsp;
		</#if>
	</div>
</#macro>


<#macro dataTableSite dataTableManager actionMacro="" tableClass="table table-striped table-condensed" caption="&nbsp;" summary="data table" >
	<#if 0 < dataTableManager.items?size >
		<#if dataTableManager.enablePaginator>
			<form class="form-inline" method="post" action="${dataTableManager.sortUrl}">
			    <#if (dataTableManager.paginator.pagesCount > 1) >
			        <@paginationSitePageLinks paginator=dataTableManager.paginator />
			    </#if>
			    <div class="pull-right">
					<@paginationSiteItemCount paginator=dataTableManager.paginator combo=1 nb_items_per_page=dataTableManager.paginator.itemsPerPage?string/>
				</div>
			</form>
		</#if>
		<table class="${tableClass}" summary="${summary}">
			<caption>${caption}</caption>
			<tr>
				<#list dataTableManager.listColumn as column>
					<th scope="col">
						#i18n{${column.titleKey}}
						<#if !(column.typeColumn = "ACTION") && column.sortable>
							<@sortSite jsp_url=dataTableManager.sortUrl attribute=column.parameterName />
						</#if>
					</th>
				</#list>
			</tr>
			<#list dataTableManager.items as item>
				<tr>
					<#list dataTableManager.listColumn as column>
						<#if column.typeColumn = "STRING">
							<#assign propName = "item." + column.parameterName>
							<#assign value = propName?eval>
							<td>${value!}</td>
						<#elseif column.typeColumn = "LABEL">
							<#assign propName = "item." + column.parameterName>
							<#assign value = propName?eval>
							<td>#i18n{${value!}}</td>
						<#elseif column.typeColumn = "BOOLEAN">
							<#assign propName = "item." + column.parameterName>
							<#assign value = propName?eval>
							<#if value?? && value>
								<td><span class="label label-success" title="#i18n{${column.labelTrue!}}"><i class="icon-ok-sign icon-white"></i>#i18n{${column.labelTrue!}}</span></td>
							<#else>
								<td><span class="label label-important" title="#i18n{${column.labelFalse!}}"><i class="icon-remove-sign icon-white"></i>#i18n{${column.labelFalse!}}</span></td>
							</#if>
						<#elseif column.typeColumn = "EMAIL">
							<#assign propName = "item." + column.parameterName>
							<#assign value = propName?eval>
							<td><#if value?? && value != ""><a href="mailto:${value}" title="${value}" >${value}</a></#if></td>
						<#elseif column.typeColumn = "ACTION">
							<#if column.parameterName?? && column.parameterName != "">
								<#assign macroName = column.parameterName>
							<#elseif actionMacro?? && actionMacro != "">
								<#assign macroName = actionMacro>
							</#if>
							<#if macroName?? && macroName != "">
								<td><@.vars[macroName] item=item /></td>
							</#if>
						</#if>
					</#list>
				</tr>
			</#list>
		</table>
		<#if dataTableManager.enablePaginator>
			<form class="form-inline" method="post" action="${dataTableManager.sortUrl}">
			    <#if (dataTableManager.paginator.pagesCount > 1) >
			        <@paginationSitePageLinks paginator=dataTableManager.paginator />
			    </#if>
			    <div class="pull-right">
					<@paginationSiteItemCount paginator=dataTableManager.paginator combo=0 nb_items_per_page=dataTableManager.paginator.itemsPerPage?string/>
				</div>
			</form>
		</#if>
	<#else>
		#i18n{portal.util.labelNoItem}
	</#if>
</#macro>

<#macro filterPanelSite dataTableManager formClass="form-horizontal" >
	<#if dataTableManager.filterPanel.listFilter?? && 0 < dataTableManager.filterPanel.listFilter?size>
		<form class="${formClass}" method="post" action="${dataTableManager.filterPanel.formUrl}" >
			<fieldset>
				<#list dataTableManager.filterPanel.listFilter as filter>
					<div class="control-group">
						<label class="control-label" for="description" >#i18n{${filter.filterLabel}} :</label>
						<div class="controls">
							<#if filter.filterType = "STRING">
								<input type="text" name="${dataTableManager.filterPanelPrefix}${filter.parameterName}" id="${filter.parameterName}" size="30" value="${filter.value!}"/>
							<#elseif filter.filterType = "BOOLEAN">
								<input type="checkbox" value="true" name="${dataTableManager.filterPanelPrefix}${filter.parameterName}" id="${dataTableManager.filterPanelPrefix}${filter.parameterName}" <#if filter.value?? && filter.value = "true">checked="checked" </#if>/>
							<#elseif filter.filterType = "DROPDOWNLIST">
								<#if filter.value??>
									<#assign filter_value = filter.value >
								<#else>
									<#assign filter_value = "" >
								</#if>
								<@comboSite name=dataTableManager.filterPanelPrefix+filter.parameterName default_value=filter_value items=filter.refList />
							</#if>
						</div>
					</div>
				</#list>
				<div class="form-actions">
					<input type="hidden" name="${dataTableManager.filterPanelPrefix}updateFilters" id="${dataTableManager.filterPanelPrefix}updateFilters" value="true" />
					<button class="btn btn-primary btn-small" type="submit" >
						<i class="icon-search icon-white"></i>
						<span class="hidden-phone" >#i18n{portal.util.labelSearch}</span>
					</button>
					<#if dataTableManager.filterPanel.formUrl?contains("?")>
						<#assign dataTableResetUrl = dataTableManager.filterPanel.formUrl + "&" + dataTableManager.filterPanelPrefix + "resetFilters=true" />
					<#else>
						<#assign dataTableResetUrl = dataTableManager.filterPanel.formUrl + "?" + dataTableManager.filterPanelPrefix + "resetFilters=true" />
					</#if>
					<a class="btn btn-primary btn-small" href="${dataTableResetUrl}" title="#i18n{portal.util.labelReset}">
						<i class="icon-remove-circle icon-white"></i>
						<span class="hidden-phone" >#i18n{portal.util.labelReset}</span>
					</a>
				</div>
			</fieldset>
		</form>
	</#if>
</#macro>

<#macro fieldInputTextSite i18nLabelKey inputName mandatory=false value="" maxlength=0 i18nHelpBlockKey='' cssClass=''>
	<div class="control-group">
		<label class="control-label" for="${inputName}">#i18n{${i18nLabelKey}} <#if mandatory>*</#if> :</label> 
		<div class="controls">
			<input class="${cssClass}" id="${inputName}" name="${inputName}" type="text" value="${value}" <#if maxlength &gt; 0>maxlength=${maxlength}</#if> />
			<#if i18nHelpBlockKey != ''><span class="help-block">#i18n{${i18nHelpBlockKey}}</span></#if>
		</div>
	</div>
</#macro>

<#macro fieldInputCalendarSite i18nLabelKey inputName mandatory=false value="" i18nHelpBlockKey='' cssClass='' language='fr'>
	<div class="control-group">
		<label class="control-label" for="${inputName}">#i18n{${i18nLabelKey}} <#if mandatory>*</#if> :</label> 
		<div class="controls">
			<div class="input-prepend">
				<span class="add-on"><i class="icon-calendar">&nbsp;</i></span>
				<input class="${cssClass}" id="${inputName}" name="${inputName}" type="text" value="${value}" />
			</div>
			<#if i18nHelpBlockKey != ''><span class="help-block">#i18n{${i18nHelpBlockKey}}</span></#if>
		</div>
	</div>
	<@getDatePicker idField=inputName language=language />
</#macro>

<#macro fieldInputCheckBoxSite i18nLabelKey inputName value="" checked=false i18nHelpBlockKey='' cssClass='' >
	<div class="control-group">
		<label class="control-label" for="${inputName}">#i18n{${i18nLabelKey}} :</label> 
		<div class="controls">
			<input class="${cssClass}" id="${inputName}" name="${inputName}" type="checkbox" value="${value}" <#if checked>checked="checked"</#if> />
			<#if i18nHelpBlockKey != ''><span class="help-block">#i18n{${i18nHelpBlockKey}}</span></#if>
		</div>
	</div>
</#macro>

<#macro fieldInputComboSite i18nLabelKey inputName items value="" mandatory=false i18nHelpBlockKey='' cssClass='' >
	<div class="control-group">
		<label class="control-label" for="${inputName}">#i18n{${i18nLabelKey}} <#if mandatory>* </#if>:</label> 
		<div class="controls">
			<#assign params = "class='" + cssClass + "'" >
			<@comboWithParams name=inputName items=items default_value=value additionalParameters=params />
			<#if i18nHelpBlockKey != ''><span class="help-block">#i18n{${i18nHelpBlockKey}}</span></#if>
		</div>
	</div>
</#macro>


<#macro fieldTextAreaSite i18nLabelKey inputName mandatory=false value="" maxlength=0 i18nHelpBlockKey='' cssClass=''>
	<div class="control-group">
		<label class="control-label" for="${inputName}">#i18n{${i18nLabelKey}} <#if mandatory>*</#if> :</label> 
		<div class="controls">
			<textarea class="${cssClass}" id="${inputName}" name="${inputName}" <#if maxlength &gt; 0>maxlength=255</#if> >${value}</textarea>
			<#if i18nHelpBlockKey != ''><span class="help-block">#i18n{${i18nHelpBlockKey}}</span></#if>
		</div>
	</div>
</#macro>